﻿using BLL;
using Function;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI.Module.User
{
    public partial class SystemMsge : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ViewState["condition"] = "ShopID in("+GetShopIDList()+")";
            }
        }

        string Message = "";
        private void Bind(string Where_String = "")
        {
            int RecordCount = 0;
            DataTable Page_Dt = new DataTable();
            Page_Dt = BLL.PageQuery2005_BLL.SelectPage(out RecordCount, "[id],[ShopID] 	,(SELECT stitle FROM dbo.ST_Shop WHERE ID=ShopID) AS shopName,[Title],[Con],[CreateTime],[CreateOpID],[LastModifyTime],[LastModifyOpID]", "[ST_SellScheme]", Where_String, "[ID] desc", Pager.CurrentPageIndex,
            Pager.PageSize, PubConstant.DataBaseTarget.JHShop, out Message);

            if (!string.IsNullOrEmpty(Message))
            {
                MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                string RemarkString;
                RemarkString = "数据查询失败";

                McBx.Title = "系统提示";
                McBx.AddContent(RemarkString);
                McBx.Type = MsgType.Error;
                McBx.AddUrl("返回", "../../Module/User/UserMsge.aspx", UrlType.Href);
                MessageEvent.MessageBox(McBx, "../../ErrorPage/ShowMsg.aspx");
                return;
            }
            grdlist.DataSource = Page_Dt;
            grdlist.DataBind();
            this.Pager.RecordCount = RecordCount;
        }

        protected void grdlist_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                int indexID = (this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize + e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = indexID.ToString();
            }
        }

        protected void Pager_BindData(object sender, EventArgs e)
        {
            Bind((ViewState["condition"] ?? "").ToString());
        }

        public string GetShopIDList()
        {
            //投资者下的门店列表信息
            string shopID = "";
            StringBuilder sb = new StringBuilder();
            DataSet shoplist = new GX_InvestorShopBLL().GetList("InvestorID=" + Method.CurrentUserID);
            foreach (DataRow item in shoplist.Tables[0].Rows)
            {
                shopID += item["ShopID"] + ",";
            }
            return ExtensionMethod.subLastChar(shopID);
        }
    }
}